<template>
  <view class="container">
    <view class="imagebox flex flex-start">
      <image class="goods-image" :src="image" mode="aspectFill"></image>
      <view class="txtbox flex flex-colum space-around align-items-top">
        <view class="name">商品名称：{{goodsname}}</view>
        <view class="doc">{{goodsdetail}}</view>
        <view class="location flex space-between">
          <!-- <view class="flex">
            <image class="icon-location" src="@/static/images/home/icon_location.png" mode=""></image>
            <text>17.88km</text>
          </view> -->
          <!-- <text class="value">￥<text style="color: #E81456;font-size: 32rpx">1</text>金币</text> -->
        </view>
      </view>
    </view>
    <view class="line mt0 flex"></view>
    <!-- <view class="tips">下单提示：请与卖家沟通后再下kjiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii/.7单</view> -->
    <view class="noticebox">
      <!-- <view class="titles">下单须知:</view> -->
      <view class="subtitle">下单前请先与卖家沟通并确认交易时间地点！</view>
      <view class="flex space-around">
        <view class="flex">
          <view class="number">1</view>
          <text>买家下单前沟通</text>
        </view>
        <view class="flex">
          <view class="number">2</view>
          <text>约定见面并验货</text>
        </view>
        <view class="flex">
          <view class="number">3</view>
          <text>确认收货</text>
        </view>
      </view>
      <p>你可与卖家沟通后协商交易地点并进行现场验货，如货不对版或和卖家描述不符，请终止交易，因是当面交易商品确认收货后概不退货</p>
    </view>

    <view class="btn-box flex space-between w100 fixed">
      <view class="line"></view>
      <view class="btns flex flex-justify-end">
        <block>
          <view class="icon flex">需支付：<text  style="color: #E81456;font-size: 40rpx">{{money}}</text>{{type == 1 ? '金币' : '元' }}</view>
          <view v-if="dealstate=='onsale'" class="btn btn-save" @click="showPopup = true"><text>确&nbsp;认&nbsp;下&nbsp;单</text></view>
          <view v-if="dealstate=='ondeal'" class="btn btn-save" @click="showPopup = false"><text>已&nbsp;被&nbsp;购&nbsp;买</text></view>
		  
        </block>
      </view>
    </view>

    <u-popup :show="showPopup" mode="center" @close="showPopup = false" :customStyle="{'borderRadius': '20rpx'}">
      <view class="popup">
        <view class="titles">是否下单</view>
        <image src="/static/images/home/close.png" mode="widthFix" @click="showPopup = false"></image>
        <text class="content">请务必先与卖家沟通好交易时间和方式，验货后完成交易，一旦付款，不支持退款退货</text>
        <view class="btns">
          <u-button type="primary" size="small" shape="circle" text="取消" color="#C4BCDF" @click="showPopup = false"></u-button>
          <u-button type="primary" size="small" shape="circle" text="确认下单" color="#7780C8" @click="orderClick"></u-button>
        </view>
      </view>
    </u-popup>
  </view>
</template>

<script>
var self, mapCtx
import QQMapWX from '../../utils/qqmap-wx-jssdk'
import MyLogin from '@/components/my-login.vue'
var qqmapsdk;

export default {
  components: {
    MyLogin
  },
  data() {
    return {
      showPopup: false,
      mediaUrl: uni.$http.mediaUrl,
      juli: '',
      goodsid: '',
      username: '',
      goodsname: '',
      dealstate: '',
      money: '',
      type: '',
      goodsdetail: '',
      goodstype: '',
      jubao_reson: '', //举报原因
      jubao_state: '',
      imagelist: [],
      image: '',
      date: '',
      nickname: '',

      latitude: '',
      longitude: '',
      address: '',
      phonesale: '',

      userInfo: null,
      ismy: false,

      dealid: '',
      showlogin: false,
    };
  },
  onLoad(e) {
    this.juli = e.juli
    this.goodsid = e.goodsid
  },
  onShow() {
    self = this
    this.userInfo = uni.getStorageSync('userInfo')
    this.getGoodsDetail()
  },
  onPullDownRefresh(e) {
    console.log("上拉")
    this.getGoodsDetail();
  },
  methods: {
    async orderClick() {
      const postmsg = {
        goodsid: this.goodsid,
        phonebuy: self.userInfo.username
      };
      const {
        data: res
      } = await uni.$http.post('geneOrder/', postmsg)
      if (res.code == 200) {
        uni.showToast({
          icon: 'success',
          title: '下单成功',
          duration: 1000
        })

        setTimeout(() => {
          uni.redirectTo({
            url: '/pages/mine/mypurchase?type=' + Number(this.type)
          })
        }, 1000);
      } else {
        uni.showToast({
          icon: 'none',
          title: res.msg,
          duration: 2000
        })

      }
    },
    fangda(item) {
      console.log(item)
      // var imgUrl = e;
      wx.previewImage({
        urls: this.imagelist, //需要预览的图片http链接列表，注意是数组
        current: '', // 当前显示图片的http链接，默认是第一个
        success: function(res) {},
        fail: function(res) {},
        complete: function(res) {},
      })
    },
    async getGoodsDetail() {
      const postmsg = {
        goodsid: this.goodsid,
		userid: uni.getStorageSync('userid'),
		
      }
      const {
        data: res
      } = await uni.$http.post('getGoodsDetail/', postmsg)
      if (res.code == 200) {
        uni.stopPullDownRefresh(); //上拉停止刷新
        this.goodsid = res.data.goodsid
        this.goodsname = res.data.goodsname
        this.goodsdetail = res.data.goodsdetail
        this.dealstate = res.data.dealstate
        this.money = res.data.money
        this.type = res.data.type
        this.goodstype = res.data.goodstype
        this.imagelist = res.data.imagelist.map((item) => `${ this.mediaUrl }${ item }`)
        this.image = this.imagelist[0]
        this.date = res.data.date
        this.address = res.data.address
        this.latitude = res.data.latitude
        this.longitude = res.data.longitude
        this.phonesale = res.data.phonesale
        this.jubao_state = res.data.jubao_state
        this.jubao_reson = res.data.jubao_reson
        this.nickname = res.data.nickname
        if (this.phonesale == self.userInfo.username) {
          this.ismy = true
        }
      } else {
        uni.showToast({
          icon: 'error',
          title: res.msg
        })
      }
    },

  },
}
</script>

<style lang="scss">
page {
  background-color: #fff;
}
.container {
  padding: 0 !important;
  .imagebox{
    height: 152rpx;
    width: 92%;
    padding: 30rpx;
    image{
      width: 152rpx;
      height: 152rpx;
      border-radius: 24rpx;
      margin-right: 36rpx;
    }
    .txtbox{
      height: 100%;
      width: 100%;
      .name{
        color: black;
		font-weight: bold;
        font-size: 28rpx;
      }
      .doc{
        color: #A99CE6;
        font-size: 22rpx;
      }
      .location{
        width: 100%;
        color: #A99CE6;
        font-size: 20rpx;
        image{
          width: 30rpx;
          height: 30rpx;
          margin-right: 3rpx;
        }
        .value{
          font-size: 24rpx;
        }
      }
    }
  }
  .tips{
    color: #EB8387;
    font-size: 22rpx;
    margin: 30rpx;
  }
  .noticebox{
    padding: 0 30rpx;
    .titles{
      color: #717176;
      font-size: 28rpx;
    }
    .subtitle{
      border-radius: 20rpx;
      background: rgb(247, 242, 255);
      color: #6B59B2;
      font-size: 28rpx;
      line-height: 2.5;
      text-align: center;
      margin: 20rpx 0;
    }
    view{
      color: #717176;
      font-size: 24rpx;
      .number{
        width: 36rpx;
        height: 36rpx;
        line-height: 36rpx;
        text-align: center;
        background: rgb(238, 239, 255);
        border-radius: 50%;
        margin-right: 5rpx;
      }
    }
    p{
      margin-top: 30rpx;
      color: #8E8E8E;
      font-size: 24rpx;
    }
  }
  .btn-box {
    margin-bottom: 0;
    // border-top: 1px solid #BFC4F2;
    padding: 8rpx 30rpx 40rpx 30rpx;
    .btns {
      flex: 1;
      .icon{
        color: #6B59B2;
        font-size: 28rpx;
        margin-right: 40rpx;
        text{
          margin-left: 5rpx;
        }
      }
      .btn {
        // min-width:220rpx;
        margin-left: 50rpx;
        margin-right: 20rpx;
        border-radius: 20rpx;
        line-height: 80rpx;
        flex: 1;

        &.btn-save {
          background: #7780C8;

          &.disabled {
            background: rgba(83, 78, 161, .6)
          }

        }

      }
    }
  }
}
.line {
  height: 1rpx;
  background: rgb(233, 235, 254);
  margin-top: 20rpx;
}
.mt0{
  margin-top: 0;
  width: 92%;
  transform: translateX(30rpx);
}

.popup{
  box-sizing: border-box;
  width: 560rpx;
  padding: 30rpx 46rpx 46rpx;
  margin: 0 auto;
  color: #5553AA;
  position: relative;
  .titles{
    color: #5553AA;
    text-align: center;
    font-size: 28rpx;
    line-height: 2;
    font-weight: bold;
  }
  image{
    width: 28rpx;
    position: absolute;
    right: 30rpx;
    top: 30rpx;
  }
  text{
    font-size: 24rpx;
    line-height: 2;
    letter-spacing: 2rpx;
  }
  .btns{
    margin-top: 50rpx;
    display: flex;
    justify-content: space-between;
    .u-button{
      width: 180rpx;
    }
  }
}
.u-safe-area-inset-bottom{
  padding-bottom: 0!important;
}


</style>
